package com.atguigu.patterns.singleton;


// 懒汉式(线程安全，同步方法)
public class SingletonDoubleCheck implements AbstractSingleton {
	private static volatile SingletonDoubleCheck instance;
	
	private SingletonDoubleCheck() {}
	
	//提供一个静态的公有方法，加入双重检查代码，解决线程安全问题, 同时解决懒加载问题
	//同时保证了效率, 推荐使用
	
	public static synchronized SingletonDoubleCheck getInstance() {
		if(instance == null) {
			synchronized (SingletonDoubleCheck.class) {
				if(instance == null) {
					instance = new SingletonDoubleCheck();
				}
			}
			
		}
		return instance;
	}
}
